//
//  QDMetroTicket.swift
//  QDMetroClient
//
//  Created by YueWen on 2019/3/6.
//  Copyright © 2019 YueWen. All rights reserved.
//

import Foundation
import HandyJSON

/// 车票的类型
enum QDTickeStatusType: String {
    /// 已支付，未领取
    case success = "0"
    /// 未支付
    case unpay = "1"
    /// 退款 其他
    case other = "2"
    /// 未知
    case unknown
}

enum QDTicketType: String {
    /// 地铁票
    case metro = "01"
    /// 未知
    case unknown
}



extension QDTicket.QDTicketState {
    
    /// 状态图片
    var statusImage: UIImage? {
        get {
            switch self {
            case .unPay: return "ticket_unpaying".namedImage
            case .unTakeout: return "ticket_untakingticket".namedImage
            case .takeout: return "ticket_takingticket".namedImage
            case .refund: return "ticket_refund".namedImage
            default: return nil
            }
        }
    }
    
    /// 按钮名称
    var buttonName: String {
        get {
            switch self {
            case .unTakeout: return "退票"
            case .refund: return "重新购票"
            default: return ""
            }
        }
    }
    
    /// 底部视图的名称
    var bottomViewName: String {
        get {
            switch self {
            case .unTakeout: return "扫码取票"
            case .unPay: return "立即支付"
            default: return ""
            }
        }
    }
}



struct QDTicket: HandyJSON {
    
    /// 车票状态
    enum QDTicketState: String {
        /// 未支付
        case unPay = "1"
        /// 未取票
        case unTakeout = "2"
        /// 已取票
        case takeout = "3"
        /// 退票
        case refund = "4"
        ///
        case unknown
    }
    
    /// 票的状态
    var ticketState = ""
    /// 订单号
    var orderNo = ""
    /// 进站名称
    var entryStation = ""
    /// 进站id
    var entryStationCode = ""
    /// 出站名称
    var exitStation = ""
    /// 出站id
    var exitStationCode = ""
    /// 票的数量
    var ticketCount = ""
    /// 取票数量
    var checkoutCount = ""
    /// 票的总价
    var ticketAmount = ""
    /// 票的单价
    var price = ""
    /// 支付渠道
    var channel = ""
    /// 下单时间
    var ticketTime = ""
    /// 所属状态的时间
    var statusTime = ""
    
    ///
    var state: QDTicket.QDTicketState {
        get {
            let state = QDTicketState(rawValue: ticketState) ?? .unknown
            return state
        }
    }
    
    var stateDesc: String {
        get {
            switch state {
            case .refund: return "已退票"
            case .takeout: return "已取票"
            case .unPay: return "未支付"
            case .unTakeout: return "未取票"
            case .unknown: return "未知状态"
            }
        }
    }
    
    /// 时间描述标题
    var stateTitleDesc: String {
        get {
            switch state {
            case .refund: return "退款时间："
            case .takeout: return "取票时间："
            case .unPay,.unTakeout: return "支付时间："
            case .unknown: return "未知状态"
            }
        }
    }
    
    var payType: QDPayType {
        get {
            return QDPayType(rawValue: channel) ?? .unknown
        }
    }
}

